package com.ccc.scala.base7_collection

import scala.collection.mutable.ArrayBuffer


object Collection07_groupBy {
  def main(args: Array[String]): Unit = {
    // 集合 - groupBy
    val array = ArrayBuffer(1, 2, 3, 4, 5)

    // 根据指定规则对每一条数据进行分组
    println(array.groupBy(num => {
      num % 2
    })) // Map(1 -> ArrayBuffer(1, 3, 5), 0 -> ArrayBuffer(2, 4))

    println(array.groupBy(_ % 2)) // Map(1 -> ArrayBuffer(1, 3, 5), 0 -> ArrayBuffer(2, 4))
  }

}
